package cn.fingersoft.jsapi.plugin.home

import android.util.Log
import cn.fingersoft.im.feature.home.HomeTabSwitchEvent
import org.greenrobot.eventbus.EventBus

class HomeTabJSApiPlugin constructor(private val context: android.app.Activity) : com.fingersoft.jsapi.JSApiPlugin() {

    override fun execute(action: String, args: org.json.JSONObject?, callbackContext: com.fingersoft.jsapi.ICallbackContext?) {
        when (action) {
            "emp.hometab.switchHomeTab" -> {
                try {
                    val id = args?.getString("id") ?: throw IllegalArgumentException("need id")
                    EventBus.getDefault().post(HomeTabSwitchEvent(id))
                } catch (e: Exception) {
                    Log.e(TAG, "${e.message}", e)
                    callbackContext?.error(e.message ?: "unknown error", "ERROR")
                }
            }
        }
    }

    companion object {
        private const val TAG = "HomeTabJSApiPlugin"
    }
}
